home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Draw / File2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  7.4 KB  |  287 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File2.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* This file is where you place various definitions and constant values for
  12. ** DTS.Lib..framework's use.  You will also add some code within the two
  13. ** functions to handle the various document types. */
  14.  
  15.  
  16.  
  17. /*****************************************************************************/
  18.  
  19.  
  20.  
  21. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  22. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  23. #include "App.protos.h"        /* Get the prototypes for the application.        */
  24.  
  25. #ifndef __ERRORS__
  26. #include <Errors.h>
  27. #endif
  28.  
  29. #ifndef __TREEOBJ2__
  30. #include "TreeObj2.h"
  31. #endif
  32.  
  33. #ifndef __UTILITIES__
  34. #include "Utilities.h"
  35. #endif
  36.  
  37.  
  38.  
  39. /* In this file, we first set some global values.  This allows the application and
  40. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  41.  
  42.  
  43. OSType        gDocCreator = kDocCreator;    /* So DTS.Lib..framework knows who's boss. */
  44.  
  45. short        gTypeListLen = 1;
  46. SFTypeList    gTypeList = {kDocFileType};
  47.     /* Here we declare the various document types that DTS.Draw can support.
  48.     8* These definitions are to inform DTS.Lib..framework what documents can be opened. */
  49.  
  50.  
  51.  
  52. /* Some DTS.Lib..framework gTypeList usage notes:
  53. **
  54. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  55. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  56. **     The index at which the match is found (+1) is used as the string number in the
  57. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  58. **     resource, then the last string is used.
  59. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  60. **     can be selected. */
  61.  
  62.  
  63.  
  64. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document */
  65.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as  */
  66.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler  */
  67.     TheDoc            doc;            /* will place on the end of each.                           */
  68. } DocFileTypeRec;
  69.  
  70.  
  71.  
  72. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  73. ** application.  The first 16 are reserved for the framework.  Our application-specific
  74. ** objects start at 16. */
  75.  
  76. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  77. /* 1  */                                         TRootObj,
  78. /* 2  */                                         TUndoObj,
  79. /* 3  */                                         TUndoTaskObj,
  80. /* 4  */                                         TUndoPartObj,
  81. /* 5  */                                         nil,
  82. /* 6  */                                         nil,
  83. /* 7  */                                         nil,
  84. /* 8  */                                         nil,
  85. /* 9  */                                         nil,
  86. /* 10 */                                         nil,
  87. /* 11 */                                         nil,
  88. /* 12 */                                         nil,
  89. /* 13 */                                         nil,
  90. /* 14 */                                         nil,
  91. /* 15 */                                         nil,
  92. /* 16        Start of app-specific procs. */         TRectObj,
  93. /* 17 */                                         TRRectObj,
  94. /* 18 */                                         TOvalObj,
  95. /* 19 */                                         TPieObj,
  96. /* 20 */                                         nil,        /* Reserve space for other   */
  97. /* 21 */                                         nil,        /* objects that may be added */
  98. /* 22 */                                         nil,        /* to the tool palette.      */
  99. /* 23 */                                         nil,        /* The group object is never */
  100. /* 24 */                                         nil,        /* going to be in the tool   */
  101. /* 25 */                                         nil,        /* palette, so put it far    */
  102. /* 26 */                                         nil,        /* enough away to leave room */
  103. /* 27 */                                         nil,        /* for other objects.        */
  104. /* 28 */                                         nil,
  105. /* 29 */                                         nil,
  106. /* 30 */                                         nil,
  107. /* 31 */                                         nil,
  108. /* 32 */                                         nil,
  109. /* 33 */                                         nil,
  110. /* 34 */                                         nil,
  111. /* 35 */                                         nil,
  112. /* 36 */                                         nil,
  113. /* 37 */                                         nil,
  114. /* 38 */                                         nil,
  115. /* 39 */                                         nil,
  116. /* 40 */                                         nil,
  117. /* 41 */                                         nil,
  118. /* 42 */                                         nil,
  119. /* 43 */                                         nil,
  120. /* 44 */                                         nil,
  121. /* 45 */                                         nil,
  122. /* 46 */                                         nil,
  123. /* 47 */                                         nil,
  124. /* 48 */                                         nil,
  125. /* 49 */                                         nil,
  126. /* 50 */                                         nil,
  127. /* 51 */                                         nil,
  128. /* 52 */                                         nil,
  129. /* 53 */                                         nil,
  130. /* 54 */                                         nil,
  131. /* 55 */                                         nil,
  132. /* 56 */                                         nil,
  133. /* 57 */                                         nil,
  134. /* 58 */                                         nil,
  135. /* 59 */                                         nil,
  136. /* 60 */                                         nil,
  137. /* 61 */                                         nil,
  138. /* 62 */                                         nil,
  139. /* 63 */                                         nil,
  140. /* 64 */                                         nil,
  141. /* 65 */                                         TGroupObj};
  142.  
  143.  
  144.  
  145. /* The framework needs to know the minimum object sizes.  This table is used by the
  146. ** framework to make sure that the object is created at least minimally. */
  147.  
  148. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  149. /* 1  */                                         sizeof(RootObj),
  150. /* 2  */                                         sizeof(UndoObj),
  151. /* 3  */                                         sizeof(UndoTaskObj),
  152. /* 4  */                                         sizeof(UndoPartObj),
  153. /* 5  */                                         0,
  154. /* 6  */                                         0,
  155. /* 7  */                                         0,
  156. /* 8  */                                         0,
  157. /* 9  */                                         0,
  158. /* 10 */                                         0,
  159. /* 11 */                                         0,
  160. /* 12 */                                         0,
  161. /* 13 */                                         0,
  162. /* 14 */                                         0,
  163. /* 15 */                                         0,
  164. /* 16        Start of app-specific sizes. */         sizeof(RectObj),
  165. /* 17 */                                         sizeof(RRectObj),
  166. /* 18 */                                         sizeof(OvalObj),
  167. /* 19 */                                         sizeof(PieObj),
  168. /* 20 */                                         0,
  169. /* 21 */                                         0,
  170. /* 22 */                                         0,
  171. /* 23 */                                         0,
  172. /* 24 */                                         0,
  173. /* 25 */                                         0,
  174. /* 26 */                                         0,
  175. /* 27 */                                         0,
  176. /* 28 */                                         0,
  177. /* 29 */                                         0,
  178. /* 30 */                                         0,
  179. /* 31 */                                         0,
  180. /* 32 */                                         0,
  181. /* 33 */                                         0,
  182. /* 34 */                                         0,
  183. /* 35 */                                         0,
  184. /* 36 */                                         0,
  185. /* 37 */                                         0,
  186. /* 38 */                                         0,
  187. /* 39 */                                         0,
  188. /* 40 */                                         0,
  189. /* 41 */                                         0,
  190. /* 42 */                                         0,
  191. /* 43 */                                         0,
  192. /* 44 */                                         0,
  193. /* 45 */                                         0,
  194. /* 46 */                                         0,
  195. /* 47 */                                         0,
  196. /* 48 */                                         0,
  197. /* 49 */                                         0,
  198. /* 50 */                                         0,
  199. /* 51 */                                         0,
  200. /* 52 */                                         0,
  201. /* 53 */                                         0,
  202. /* 54 */                                         0,
  203. /* 55 */                                         0,
  204. /* 56 */                                         0,
  205. /* 57 */                                         0,
  206. /* 58 */                                         0,
  207. /* 59 */                                         0,
  208. /* 60 */                                         0,
  209. /* 61 */                                         0,
  210. /* 62 */                                         0,
  211. /* 63 */                                         0,
  212. /* 64 */                                         0,
  213. /* 65 */                                         sizeof(GroupObj)};
  214.  
  215.  
  216.  
  217. /*****************************************************************************/
  218. /*****************************************************************************/
  219.  
  220.  
  221.  
  222. /* •• Called by DTS.Lib..framework. •• */
  223.  
  224. /* Do any additional document initialization here.  All fields not specifically set
  225. ** are already initialized to 0. */
  226.  
  227. #pragma segment File
  228. OSErr    InitDocument(FileRecHndl frHndl)
  229. {
  230.     OSErr    err;
  231.  
  232.     err = noErr;
  233.  
  234.     switch ((*frHndl)->fileState.sfType) {
  235.         case kDocFileType:
  236.             err = DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos);
  237.             if (!err) {
  238.                 (*frHndl)->d.doc.fhInfo.hDocSize = (7 * 72);
  239.                 (*frHndl)->d.doc.fhInfo.vDocSize = (10 * 72);
  240.             }
  241.             break;
  242.         case kClipboardFileType:
  243.             ClipboardInitDocument(frHndl);
  244.             break;
  245.         case kToolFileType:
  246.             return(ToolInitDocument(frHndl));
  247.             break;
  248. #if VH_VERSION
  249.         case kViewHierFileType:
  250.             return(VHInitDocument(frHndl));
  251.             break;
  252. #endif
  253.     }
  254.  
  255.     return(err);
  256. }
  257.  
  258.  
  259.  
  260. /*****************************************************************************/
  261.  
  262.  
  263.  
  264. /* •• Called by DTS.Lib..framework. •• */
  265.  
  266. /* Return the initial size of the primary document handle, based on the OSType. */
  267.  
  268. #pragma segment File
  269. long    InitDocumentSize(OSType sftype)
  270. {
  271.     switch (sftype) {
  272.         case kDocFileType:
  273.         case kClipboardFileType:
  274.         case kToolFileType:
  275.             return(sizeof(DocFileTypeRec));
  276.             break;
  277. #if VH_VERSION
  278.         case kViewHierFileType:
  279.             return(VHFileTypeSize());
  280.             break;
  281. #endif
  282.     }
  283. }
  284.  
  285.  
  286.  
  287.